package com.neosavvy.grid {
    import flash.utils.describeType;

    public dynamic class PickFilterRow {

        private var _selected:Boolean = false;

        private var _wrappedObject:Object;

        public function PickFilterRow(selected:Boolean, wrappedObject:Object, forceDescribeType:Boolean = false, passedAccessors:Array = null) {

            _selected = selected;
            _wrappedObject = wrappedObject;

            proxyWrappedObject(wrappedObject, passedAccessors);
        }

        public function get selected():Boolean {
            return _selected;
        }

        public function set selected(value:Boolean):void {
            _selected = value;
        }

        public function get wrappedObject():Object {
            return _wrappedObject;
        }

        protected static function getNonstaticAccessors(classOfInterest:Object):Array {
            if (accessors)
                return accessors;

            //Init array
            var accessors:Array = [];

            if (!xmlDescriptionOfClass)
                var xmlDescriptionOfClass:XML = describeType(classOfInterest);

            var nonstaticAccessorsXML:XMLList = xmlDescriptionOfClass.accessor;
            for each (var accessorXML:XML in nonstaticAccessorsXML) {
                accessors.push(accessorXML.@name.toString());
            }
            return accessors;
        }


        protected function proxyWrappedObject(wrappedObject:Object, passedAccessors:Array = null):void {
            var accessorNames:Array = (passedAccessors == null) ? getNonstaticAccessors(wrappedObject) : passedAccessors;

            for each (var accessorName:String in accessorNames) {
                var accessorValue:Object = wrappedObject[accessorName];
                this[accessorName] = accessorValue;
            }
        }

    }
}